{% extends 'web/layout/basic.html' %}
{% load static %}

{% block title %}用户登录{% endblock %}

{% block css %}
    <link rel="stylesheet" href="{% static 'css/account.css' %}">
{% endblock %}

{% block content %}
    <div class="account">
        <div class="title">用户登录</div>
        <form id="form" method="POST" novalidate>
            {% csrf_token %}
            {% for field in form %}
                {% if field.name == 'code' %}
                    <div class="form-group">
                        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                        <div class="clearfix">
                            <div class="col-xs-7" style="padding-left: 0">
                                {{ field }}
                                <span class="error-msg">{{ field.errors.0 }}</span>
                            </div>
                            <div class="col-xs-5" style="padding-right: 0"><img id="image_code" src="{% url 'image_code' %}" title="看不清？点击换一张" alt=""></div>
                        </div>
                    </div>
                {% elif field.name == 'password' %}
                    <div class="form-group">
                        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                        <a href="#" style="float: right">忘记密码？</a>
                        {{ field }}
                        <span class="error-msg">{{ field.errors.0 }}</span>
                    </div>
                {% else %}
                    <div class="form-group">
                        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                        {{ field }}
                        <span class="error-msg">{{ field.errors.0 }}</span>
                    </div>
                {% endif %}
            {% endfor %}
            <div class="row">
                <div class="col-xs-7">
                    <input id="btnSubmit" type="submit" class="btn btn-primary col-md-12" value="登  录">
                </div>
                <a class="col-xs-5 login-style" href="{% url 'login_sms' %}">短信登录</a>
            </div>
        </form>
    </div>
{% endblock %}

{% block js %}
    <script>
        // 页面加载完成之后自动执行的函数
        $(function () {
            BindClickImageCode();
        });
        // 点击更换验证码图片
        function BindClickImageCode() {
            $('#image_code').click(function () {
                let oldSrc = $(this).attr('src');
                $(this).attr('src', oldSrc + '?');
            })
        }
    </script>
{% endblock %}